package org.study.dynamic.ds.controller;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.study.dynamic.ds.service.DatabaseTableService;
import org.study.dynamic.ds.vo.ColumnInfoVo;
import org.study.dynamic.ds.vo.TableInfoVo;

import java.util.List;

/**
 * 数据库、表、字段信息
 *
 * @author doveylovey
 * @version v1.0.0
 * @email 1135782208@qq.com
 * @date 2023年06月09日
 */
@Slf4j
@RestController
@RequestMapping("/ds")
@AllArgsConstructor
public class DatabaseTableController {
    private DatabaseTableService databaseTableService;

    @GetMapping("/mysql/getTables")
    public List<TableInfoVo> getTables() {
        // 获取当前数据库中的所有表
        List<TableInfoVo> tables = this.databaseTableService.getTables4Mysql(null);
        return tables;
    }

    @GetMapping("/mysql/getColumns/{tableName}")
    public List<ColumnInfoVo> getColumns(@PathVariable("tableName") String tableName) {
        // 获取指定表的字段信息
        List<ColumnInfoVo> columns = this.databaseTableService.getColumns4Mysql(null, tableName);
        return columns;
    }
}
